<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php $_code=$this->getMethodCode() ?>
<ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display: none">
    <li>
        <div class="input-box">
            <div class="v-fix" style="float: left; padding-right: 10px;">
                <select id="ewayrapid_saved_token" name="payment[saved_token]" class="ewayrapid_saved_token">
                    <?php
                        $_tokens = $this->getTokenList();
                        $_defaultToken = isset($_tokens['default_token']) ? $_tokens['default_token'] : false;
                    ?>
                    <?php foreach($_tokens['tokens'] as $_key => $_token): ?>
                        <?php /* @var Eway_Rapid31_Model_Customer_Token $_token */ ?>
                        <option value="<?php echo $_key ?>" <?php if($_key == $_defaultToken): ?>selected="selected"<?php endif; ?>>
                            <?php echo $_token->getCard() ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <?php if(count($_tokens['tokens']) > 1): ?>
                <div class="v-fix">
                    <a id="ewayrapid_saved_edit" class="ewayrapid_saved_edit" href="javascript:void(0);"><?php echo $this->__('Edit') ?></a>
                </div>
            <?php endif; ?>
        </div>
        <div style="clear: both;"></div>
    </li>

    <li class="saved_token_fields" style="display: none">
        <div class="input-box">
            <label for="<?php echo $_code ?>_cc_owner"><?php echo $this->__('Name on Card') ?> <span class="required">*</span></label>
            <br/>
            <input type="text" title="<?php echo $this->__('Name on Card') ?>" class="input-text required-entry" id="<?php echo $_code ?>_cc_owner" name="payment[cc_owner]" value="<?php echo $this->htmlEscape($this->getInfoData('cc_owner')) ?>" />
        </div>
    </li>
    <li class="saved_token_fields" style="display: none">
        <label for="<?php echo $_code ?>_cc_number"><?php echo $this->__('Credit Card Number') ?> <span class="required">*</span></label>
        <br/>
        <div class="input-box">
            <input type="text" id="<?php echo $_code ?>_cc_number" data-eway-encrypt-name="payment[cc_number]" title="<?php echo $this->__('Credit Card Number') ?>" class="input-text validate-cc-number validate-cc-type-auto" value="" />
            <input type="hidden" id="<?php echo $_code ?>_cc_type" name="payment[cc_type]" />
        </div>
    </li>
    <li id="<?php echo $_code ?>_cc_type_exp_div" class="saved_token_fields" style="display: none">
        <div class="input-box">
            <label for="<?php echo $_code ?>_expiration"><?php echo $this->__('Expiration Date') ?> <span class="required">*</span></label>
            <br/>
            <select id="<?php echo $_code ?>_expiration" name="payment[cc_exp_month]" class="month validate-cc-exp required-entry">
            <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
            <?php foreach ($this->getCcMonths() as $k=>$v): ?>
                <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
            <?php endforeach ?>
            </select>
            <?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
            <select id="<?php echo $_code ?>_expiration_yr" name="payment[cc_exp_year]" class="year required-entry">
            <?php foreach ($this->getCcYears() as $k=>$v): ?>
                <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
            <?php endforeach ?>
            </select>
        </div>
    </li>
    <?php echo $this->getChildHtml() ?>
    <script type="text/javascript">
        var ewayPaymentToken = new EwayPaymentToken(
            <?php echo $_tokens['tokens_json'] ?>,
            <?php echo count($_tokens['tokens']) ?>,
            true,
            '<?php echo $this->__('Edit') ?>',
            '<?php echo $this->__('Cancel edit') ?>'
        )

        if(typeof AdminOrder.prototype.setPaymentMethodBackup == "undefined") {
            AdminOrder.prototype.setPaymentMethodBackup = AdminOrder.prototype.setPaymentMethod;
            AdminOrder.prototype.setPaymentMethod = function(method) {
                AdminOrder.prototype.setPaymentMethodBackup(method);
                if(EwayPayment.isEwayRapidMethod(method)) {
                    ewayPaymentToken.onSavedTokenChanged();
                }
            }
        }
    </script>
</ul>

